{extend name="common/base" /}

{block name="title"}<title>{$title}</title>{/block}

{block name="main"}
<div class="layui-fluid table">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-form" lwid100="" iwid300="" lay-filter="form">

                        {include file="common/form" /}

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="form">保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="alert" value="1">
{/block}


<script>
    {block name="layui_table"}
    laydate.render({
        elem: '#time_start'
        ,type: 'datetime'
    });
    var index = parent.layer.getFrameIndex(window.name);

    $('#close').on("click",function () {
        parent.layer.close(index);
    });

    form.on('submit(form)', function(data){
        var data = form.val('form');
        if($('#alert').val() == 1){
            $('#alert').val(2);
            $.ajax({
                url: '/backmanage/anchor/create'
                ,data: data
                ,type: 'POST'
                ,headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
                ,success(res){
                    if(typeof  res == "string"){
                        res = JSON.parse(res);
                    }
                    if (res.code == 0){
                        parent.layer.close(index);
                        parent.layer.msg(res.msg, {icon: 1});
                        parent.layui.table.reload('table');
                    } else if($('#alert').val() ==2){
                        if(res.code == -100){
                            console.log(-100);
                            $('#alert').val(1);
                        }
                        layer.msg(res.msg);
                    }
                }
            }).fail(function(msg){
                $('#alert').val(1);
                layer.open({
                    content: '操作失败,请稍候再试',
                    btn: ['OK']
                });
            });
        }
    });


    var list_url,cols ='';
    {/block}
</script>

